package org.ruixue.controller;

import cn.rkylin.oms.common.dto.DBLog;
import com.alibaba.fastjson.JSON;
import org.ruixue.response.BaseResponse;
import org.ruixue.service.ShopService;
import org.ruixue.util.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    LogUtil logUtil;

    @Autowired
    ShopService shopService;

    /**
     * http://localhost:40005/microservice-yiyouyayin/shop/downloadYiShop
     * 网店（商户）同步下载
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/downloadYiShop", method = RequestMethod.GET)
    private ResponseEntity<BaseResponse> downloadYiShop() {
        BaseResponse response = new BaseResponse();
        try {
            response = shopService.downloadYiShop();
            logUtil.info(new DBLog("", "", "downloadYiShop", JSON.toJSONString(response)));
        } catch (Exception e) {
            e.printStackTrace();
            response.setMsg(e.getMessage());
            response.setSuccess("false");
            logUtil.error(new DBLog("", "", "downloadYiShop", e.getMessage()), e);
        }
        return new ResponseEntity<BaseResponse>(response, HttpStatus.OK);
    }
}
